package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 晨子
 * date2024/6/1117:05
 */

/*
对象储存服务配置
 */
@Configuration
@Slf4j
public class OssConfiguration {
    //@Autowired
    //private AliOssProperties aliOssProperties;

    @Bean
    @ConditionalOnMissingBean  //当spring容器中没有指定对象时，才会执行此方法
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties) {
        log.info("开始创建OSS工具类对象。。。");
        return new AliOssUtil(
                aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName()
        );
    }
}
